#bilibili用户管理系统

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
import project
from index import *
import hashlib
import enter_ui
import tu_rc
import sys

# UI--Logic分离
reset, _ = loadUiType('reset.ui')

class ResetApp(QMainWindow,reset):

    #定义构造方法
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.handle_buttons()
        self.show()

    def handle_buttons(self):
        self.reset_agree_Button.clicked.connect(self.editor_user)
        self.reset_back_Button.clicked.connect(self.enter)


    def enter(self):
        self.enter_app = enter_ui.EnterApp()
        self.close()
        self.enter_app.show()

    def editor_user(self):
        # 1、获取连接
        conn = get_conn()
        # 2、获取cursor
        cur = conn.cursor()
        # 3、SQl语句
        sql = "update users set " \
              "user_pwd = %s" \
              " where user_num=%s"
        user_num = self.reset_num_Edit.text()
        user_pwd = self.reset_password_Edit.text()
        user_confirm_pwd = self.reset_agreepassword_Edit.text()
        if user_pwd == user_confirm_pwd:
            # 加密
            hash = hashlib.md5(bytes("禾木AI", encoding="utf-8"))
            hash.update(bytes(user_pwd, encoding="utf-8"))
            user_pwd_hash = hash.hexdigest()
            reply = QMessageBox.question(self, '确认', '确定更改?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if reply == QMessageBox.Yes:
                # 4、执行语句
                values = (user_pwd_hash, user_num)
                cur.execute(sql, values)
                # 5、insert、update、delete必须显示提交
                conn.commit()
                '''
                self.statusBar().showMessage('密码重置成功！')
                self.self.reset_num_Edit.setText('')
                self.reset_password_Edit.setText('')
                self.reset_agreepassword_Edit.setText('')
                '''
                self.enter_app = enter_ui.EnterApp()
                self.close()
                self.enter_app.show()
        else:
            self.statusBar().showMessage("两次密码不一致")
            self.reset_password_Edit.setText('')
            self.reset_agreepassword_Edit.setText('')

def main():
    app = QApplication([])
    window = ResetApp()
    window.show()
    app.exec_()


if __name__ == '__main__':
    main()

